<!DOCTYPE HTML>
<html>
<head>
	<?php
		include("include.php");
		
		if(!empty($_POST['action']) && $_POST['action'] == 'save')
		{
			$gen = $_POST['generalSelect'];
			$crt = $_POST['creatorsSelect'];
			$mod = $_POST['moderatorsSelect'];
			
			echo '<pre>'.print_r($gen, true).'</pre>';
			echo '<pre>'.print_r($crt, true).'</pre>';
			echo '<pre>'.print_r($mod, true).'</pre>';
			die();
		}
		
		$allUsers = userHelper::getAllUsersWithType();
		$general = $allUsers[1];
		$creators = $allUsers[2];
		$moderators = $allUsers[3];
	?>
	
	<style>
		.select{ width:200px; margin:1px; display:inline-block; float:left; }
		.select h3{ text-align:center; font-size:16px; }
		select{ width:200px; }
		.moveButtons{ display:inline-block; float:left; margin-top:45px; width:33px; }
		input{ display:block; padding:5px 3px; margin:6px 4px; color:#2EB1C1; border:1px solid #494037; border-radius:3px; 
			background-color:#797067; 
			background: -webkit-gradient(linear, left top, left bottom, from(#797067), to(#262624));
			background: -moz-linear-gradient(top,  #797067,  #262624);
			filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#797067', endColorstr='#262624'); }
	</style>
				
</head>
<body>

<div class="container">
	<div id="header">
		<?php include("banner.php")?>
		
		<div id="login">
			<?php login::displayLoginDiv(); ?>
		</div>
		
		<div class="clear"></div>
		
		<div id="navigation">
			<?php include('navigation.php'); ?>
		</div>
	</div>
	
	<div class="clear"></div>
	
	<div id="body">
		<div id="content">
			<h1>Edit User Access</h1>
				
			<form name="allUsersAccess">
				
				<div class="select">
					<h3>General Users</h3>
					<select multiple="multiple" name="generalSelect" size="10">
						<?php foreach($general as $ID => $name){ ?>
						<option value="<?php echo $ID; ?>"><?php echo $name; ?></option>
						<?php } ?>
					</select>
				</div>
				
				<div class="moveButtons">
					<input type="button" value="--&gt;" onclick="moveOptions(this.form.generalSelect, this.form.creatorsSelect);" /><br/>
					<input type="button" value="&lt;--" onclick="moveOptions(this.form.creatorsSelect, this.form.generalSelect);" />
				</div>
				
				<div class="select">
					<h3>Content Creators</h3>
					<select multiple="multiple" name="creatorsSelect" size="10">
						<?php foreach($creators as $ID => $name){ ?>
						<option value="<?php echo $ID; ?>"><?php echo $name; ?></option>
						<?php } ?>
					</select>
				</div>
				
				<div class="moveButtons">
					<input type="button" value="--&gt;" onclick="moveOptions(this.form.creatorsSelect, this.form.moderatorsSelect);" /><br />
					<input type="button" value="&lt;--" onclick="moveOptions(this.form.moderatorsSelect, this.form.creatorsSelect);" />
				</div>
				
				<div class="select">
					<h3>Moderators</h3>
					<select multiple="multiple" name="moderatorsSelect" size="10">
						<?php foreach($moderators as $ID => $name){ ?>
						<option value="<?php echo $ID; ?>"><?php echo $name; ?></option>
						<?php } ?>
					</select>
				</div>
			</form>
				
				<div class="clear spacer"></div>
				<input id="saveAccess" type="submit" class="submit" value="Save">
				<div id="ajaxResponse" style="display:inline-block; margin-left:5px"></div>
			
			<script>
				$("#saveAccess").click(function (){
					saveA();
				});
				
				function saveA()
				{
					var genForm = document.forms['allUsersAccess']['generalSelect'];
					var gen = new Array();
					var genLength = genForm.length;
					for(var i=0; i<genLength; i++)
						gen[i] = genForm.options[i].value;

					var crtForm = document.forms['allUsersAccess']['creatorsSelect'];
					var crt = new Array();
					var crtLength = crtForm.length;
					for(var i=0; i<crtLength; i++)
						crt[i] = crtForm.options[i].value;

					var modForm = document.forms['allUsersAccess']['moderatorsSelect'];
					var mod = new Array();
					var modLength = modForm.length;
					for(var i=0; i<modLength; i++)
						mod[i] = modForm.options[i].value;
					//alert('here');
					//alert(gen);
					//alert(crt);
					//alert(mod);
					
					var xmlHttp = getXMLHttp();
					  
					xmlHttp.onreadystatechange = function()
					{
						if(xmlHttp.readyState == 4)
						{
							HandleResponse(xmlHttp.responseText);
						}
					}

					xmlHttp.open("GET", "updateUserType.php?gen="+gen+"&crt="+crt+"&mod="+mod, true); 
					//xmlHttp.open("GET", "updateUserType.php?gen=yes", true); 
					xmlHttp.send(null);
					//alert("end");
					
				}
			
			</script>
			
			
		</div>
		<div id="tags">
			<h1>Tags</h1>
			<?php tag::displayTagCloud(); ?>
		</div>
		
		<div id="fblike">
			<?php include "facebookLike.php"; ?>
        </div>
	
	</div>
	
	<div class="clear"></div>
	
	<div id="footer">
		<?php include("footer.php"); ?>
	</div>

</div>


</body>
</html>